<?php
include_once('common/header.php');	
if($AppUI->id <= 0 || !isset($_SERVER['HTTP_REFERER'])) {
	$this->_redirect(HOST_VFRIEND);
}
$strRefer			= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$intTlikeConvert	= (int)$objRequest->getParam('ptlike',0);
$strToken			= $objRequest->getParam('token','');
$strSession			= isset($_SESSION['vConvert' . $AppUI->id]) ? $_SESSION['vConvert' . $AppUI->id] : '';
$intError			= 0;
$objVfriendUser		= new Vfriend_User();
$objUstat			= $objVfriendUser->getUserStat($AppUI->id);
$intTlike			= $objUstat['tlike'];
if($intTlikeConvert == 0 || !isset($intTlikeConvert)) {
	$intError	= 38;
}elseif($intTlikeConvert && $intTlikeConvert < RATE_CONVERT_VON){
	$intError	= 39;
}elseif($intTlike < $intTlikeConvert && $intTlikeConvert) {
	$intError	= 40;
}elseif($intTlikeConvert && strlen($intTlikeConvert) > 8) {
	$intError	= 41;
}
if($intError == 0) {
	if($strToken != '' && $strSession != '' && $strToken == $strSession && Vfriend_Function::isValidLink($strRefer)) {
		unset($_SESSION['vConvert' . $AppUI->id]);
		$intVon		= round($intTlikeConvert/RATE_CONVERT_VON,0);
		$intError	= $objVfriendUser->updateUstatConvertVon($AppUI->id, $intTlikeConvert, $intVon);
		if($intError == 0) {
			Vfriend_Function::setMsg($arrMessage[17]);
		} else {
			$intError 	= 42; 
		}
	} else {
		$intError	= 43;
	}
}
if($intError > 0) {
	Vfriend_Function::setError($arrError[$intError]);
}
Vfriend_Function::redirect($strRefer ? $strRefer : HOST_VFRIEND);
?>